"""SQL解析器基类模块"""

import re
from abc import ABC, abstractmethod
from typing import Dict, Any
from src.service.preprocess.preprocess_sql_service import SQLPreprocessService, PreprocessResult

class SQLParserBase(ABC):
    """SQL解析器基类"""

    def __init__(self):
        self.preprocessor = SQLPreprocessService()

    def parse_sql(self, sql: str) -> Dict[str, Any]:
        """解析SQL语句

        Args:
            sql: SQL语句

        Returns:
            Dict[str, Any]: 解析结果
        """
        # 预处理SQL
        preprocess_result = self.preprocessor.preprocess(sql)

        # 解析预处理后的SQL
        parse_result = self._parse_sql(preprocess_result.cleaned_sql)

        return parse_result

    @abstractmethod
    def _parse_sql(self, sql: str) -> Dict[str, Any]:
        """解析预处理后的SQL语句

        Args:
            sql: 预处理后的SQL语句

        Returns:
            Dict[str, Any]: 解析结果
        """
        pass

    def parse_file(self, file_path: str) -> Dict[str, Any]:
        """解析SQL文件

        Args:
            file_path: SQL文件路径

        Returns:
            解析结果字典
        """
        pass